package com.dream.controller;

import com.dream.pojo.TempRecord;
import com.dream.service.TempRecordService;
import com.dream.service.impl.TempRecordServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Date;

@WebServlet("/TempRecordController.do")
public class TempRecordController extends BaseServlet{
    TempRecordService tempRecordService = new TempRecordServiceImpl();

    public void add(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
        String stuId = request.getParameter("stuId");
        String recordDate = request.getParameter("recordDate");
        String stuTemp = request.getParameter("stuTemp");
        String symptom1 = request.getParameter("symptom1");
        String symptom2 = request.getParameter("symptom2");
        TempRecord tempRecord = new TempRecord(stuId, Date.valueOf(recordDate),stuTemp,symptom1,symptom2);
        int count = tempRecordService.addTempRecord(tempRecord);
        if (count>0){
            response.getWriter().write("<script>alert('体温提交成功');location.href='tempRecord.jsp';</script>");
        }else {
            response.getWriter().write("<script>alert('体温提交异常');location.href='tempRecord.jsp';</script>");
        }
    }
}
